# -*- coding:utf8 -*-
'''
Created on 2019年8月8日

@author: Administrator
'''
import requests
import lxml.html
import re
from lxml import html
import urllib 
import json
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from urllib.parse import quote
from pyquery import PyQuery as pq

#https://list.tmall.com/search_product.htm?q=

browser = webdriver.Firefox()

#browser.get('http://www.baidu.com')
#browser.close()

wait = WebDriverWait(browser,10)
try:
    a=input('请输入商品')
    url='https://list.tmall.com/search_product.htm?q='+quote(a)
    
    browser.get(url)
    html = browser.page_source
    doc = pq(html)
    items = doc('.product-iWrap').items()
    for item in items:
     
        print(item.find('.productShop-name'))
        pro ={
            '店铺名':item.find('.productShop-name').text(),
            '成交量':item.find('.productStatus').text(),
            '图片地址':item.attr('src'),
            '内容':item.find('.productTitle a').text(),
            '价格':item.find('.productPrice').text()
            }
        print(pro)
except TimeoutException:
    print('出错了')
finally:
    browser.close()

